//
//  CourseListViewController.m
//  KeepProject
//
//  Created by amos on 16/1/20.
//  Copyright © 2016年 itheima. All rights reserved.
//

#import "CoursePlan.h"
#import "CoursePlanCell.h"
#import "CoursePlanListViewController.h"
@interface CoursePlanListViewController ()
@property (nonatomic, strong) NSArray* plans;
@end

@implementation CoursePlanListViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{

    return self.plans.count;
}

- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
    //1.取出对应的 plan模型
    CoursePlan* plan = self.plans[indexPath.row];

    static NSString* ID = @"planCell";

    if ([plan.type isEqualToString:@"once"]) {
        ID = @"onceCell";
    }
    else {
        ID = @"planCell";
    }

    CoursePlanCell* cell = [tableView dequeueReusableCellWithIdentifier:ID forIndexPath:indexPath];

    cell.plan = plan;

    return cell;
}

- (CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath
{
    //1.获取当前 cell 对应的模型
    CoursePlan* plan = self.plans[indexPath.row];
    //2.判断模型的类型
    if ([plan.type isEqualToString:@"once"]) {
        return 100;
    }
    return 150;
}

#pragma mark - 懒加载
- (NSArray*)plans
{
    if (!_plans) {
        NSLog(@"%@", self.sourceURL);
        _plans = [CoursePlan plansFromPlist:self.sourceURL];
    }
    return _plans;
}

@end
